home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 4 / The 640 Meg Shareware Studio CD-ROM Volume IV (Data Express)(1994).ISO / clang / 114_01.zip / ED8.BDS < prev    next >
Text File  |  1993-06-01  |  5KB  |  286 lines

  1. /* Screen editor:  operating system module
  2.  *           BDS C version
  3.  *
  4.  * Source:  ed8.cc
  5.  * Version: June 19, 1981.
  6.  */
  7.  
  8. /* define globals */
  9.  
  10. #include ed.h
  11. #include bdscio.h
  12. #include ed1.ccc
  13. #include edext.cc
  14.  
  15. /* globals used by this module -----
  16.  
  17. #define NSECTS 8
  18. #define SECSIZ 128
  19. #define BUFSIZ (NSECTS * SECSIZ + 6)
  20.  
  21. int  iormode;        'r' 'w' or 'c'
  22. char iobuf1[BUFSIZ];    file buffer
  23.  
  24. ----- */
  25.  
  26. /* all calls to the operating system are made here.
  27.  * only this module will have to be
  28.  * rewritten for a new operating system.
  29.  */
  30.  
  31. /* the routines syscstat(), syscin() and syscout() come in
  32.  * two flavors:  CP/M version 2.2 and CP/M version 1.4.
  33.  * Comment out which ever you don't use.
  34.  */
  35.  
  36. /* CP/M 2.2 versions of syscstat(), syscin(), syscout() */
  37.  
  38. /* return -1 if no character is ready from the console. 
  39.  * otherwise, return the character.
  40.  */
  41.  
  42. syscstat()
  43. {
  44.     return(bdos(6,-1));
  45. }
  46.  
  47. /* wait for next character from the console.
  48.  * do not echo it.
  49.  */
  50.  
  51. syscin()
  52. {
  53. int c;
  54.     while ((c=bdos(6,-1))==0) {
  55.         ;
  56.     }
  57.     return(c);
  58. }
  59.  
  60. /* print character on the console */
  61.  
  62. syscout(c) char c;
  63. {
  64.     bdos(6,c);
  65.     return(c);
  66. }
  67.  
  68. /* CP/M 1.4 versions of syscstat(), syscin(), syscout() */
  69.  
  70. /* start comment out ----------
  71. syscstat()
  72. {
  73.     if (bios(2,0)==255) {
  74.         return(-1);
  75.     }
  76.     else {
  77.         return(0);
  78.     }
  79. }
  80.  
  81. syscin()
  82. {
  83.     return(bios(3,0));
  84. }
  85.  
  86. syscout(c) char c;
  87. {
  88.     bios(4,c);
  89.     return(c);
  90. }
  91. ---------- end comment out */
  92.  
  93.  
  94. /* print character on the printer */
  95.  
  96. syslout(c) char c;
  97. {
  98.     bdos(5,c);
  99.     return(c);
  100. }
  101.  
  102. /*
  103.  * return address of last usable memory location.
  104.  */
  105.  
  106. sysend()
  107. {
  108.     return(topofmem());
  109. }
  110.  
  111. /* open a file */
  112.  
  113. sysopen(name,mode) char *name, *mode;
  114. {
  115. int file;
  116. int m;
  117.     m=tolower(mode[0]);
  118.     if (m=='r') {
  119.         if ((file=fopen(name,iobuf1))==-1) {
  120.             iormode='c';
  121.             fclose(iobuf1);
  122.             return(ERR);
  123.         }
  124.         else {
  125.             iormode=m;
  126.             return(iobuf1);
  127.         }
  128.     }
  129.     else if (m=='w') {
  130.         if ((file=fcreat(name,iobuf1))==-1) {
  131.             iormode='c';
  132.             fclose(iobuf1);
  133.             return(ERR);
  134.         }
  135.         else {
  136.             iormode=m;
  137.             return(iobuf1);
  138.         }
  139.     }
  140.     else {
  141.         iormode='c';
  142.         syserr("fopen: bad mode");
  143.         return(ERR);
  144.     }
  145. }
  146.  
  147. /* close a file */
  148.  
  149. sysclose(file) int file;
  150. {
  151.     if (iormode=='w') {
  152.         /* write end of file byte */
  153.         putc(0x1a,iobuf1);
  154.         fflush(iobuf1);
  155.     }
  156.     iormode='c';
  157.     fclose(iobuf1);
  158.     return(OK);
  159. }
  160.  
  161. /* read next char from file */
  162.  
  163. sysrdch(file) int file;
  164. {
  165. int c;
  166.     while ((c=sysrdc1())==LF) {
  167.         ;
  168.     }
  169.     return(c);
  170. }
  171.  
  172. sysrdc1()
  173. {
  174. int c;
  175.     if (iormode!='r') {
  176.         error ("sysrdch:  read in w mode");
  177.         return(ERR);
  178.     }
  179.     if ((c=getc(iobuf1))==-1) {
  180.         return(EOF);
  181.     }
  182.     else if (c==0x1a) {
  183.         return(EOF);
  184.     }
  185.     else {
  186.         return(c);
  187.     }
  188. }
  189.  
  190. /* write next char to file */
  191.  
  192. syspshch(c,file) char c; int file;
  193. {
  194.     if (c!=CR) {
  195.         return(syspshc1(c,file));
  196.     }
  197.     else if (syspshc1(c,file)==ERR) {
  198.         return(ERR);
  199.     }
  200.     else {
  201.         return(syspshc1(LF,file));
  202.     }
  203. }
  204.  
  205. syspshc1(c,file) char c; int file;
  206. {
  207.     if (iormode!='w') {
  208.         error("syspshch:  write in r mode");
  209.         return(ERR);
  210.     }
  211.     if (putc(c,iobuf1)==-1) {
  212.         error("disk write failed");
  213.         return(ERR);
  214.     }
  215.     else {
  216.         return(c);
  217.     }
  218. }
  219.  
  220. /* read one char from END of file */
  221.  
  222. syspopch(file) int file;
  223. {
  224.     error("syspopch() not implemented");
  225.     return(ERR);
  226. }
  227.  
  228. /* check file name for syntax */
  229.  
  230. syschkfn(args) char *args;
  231. {
  232.     return(OK);
  233. }
  234.  
  235. /* copy file name from args to buffer */
  236.  
  237. syscopfn(args,buffer) char *args, *buffer;
  238. {
  239. int n;
  240.     n=0;
  241.     while (n<(SYSFNMAX-1)) {
  242.         if (args[n]==EOS) {
  243.             break;
  244.         }
  245.         else {
  246.             buffer[n]=args[n];
  247.             n++;
  248.         }
  249.     }
  250.     buffer[n]=EOS;
  251. }
  252.  
  253. /* move a block of n bytes down (towards HIGH addresses).
  254.  * block starts at source and the first byte goes to dest.
  255.  * this routine is only called from bufmovdn() as follows:
  256.  *    sysmovdn( n=to-from+1, dest=to+length, source=to);
  257.  */
  258.  
  259. sysmovdn(n,dest,source) int n; char *dest, *source;
  260. {
  261.     if (n>0) {
  262.         movmem(source-n+1,dest-n+1,n);
  263.     }
  264. }
  265.  
  266. /* move a block of n bytes up (towards LOW addresses).
  267.  * the block starts at source and the first byte goes to dest.
  268.  * this routine is called only from bufmovup() as follows:
  269.  *     sysmovup( n=to-from+1, dest=from-length, source=from);
  270.  */
  271.  
  272. sysmovup(n,dest,source) int n; char *dest, *source;
  273. {
  274.     if (n>0) {
  275.         movmem(source,dest,n);
  276.     }
  277. }
  278.  
  279. e name for syntax */
  280.  
  281. syschkfn(args) char *args;
  282. {
  283.     return(OK);
  284. }
  285.  
  286. /* copy file name fr